import {
    BrowserWindow,
    dialog,
    app,
    Notification,
    nativeImage,
    screen
  } from "electron";
  const path = require("path");
  import BaseWindow from "./baseWin";
  
  export default class MainWindow extends BaseWindow {
    constructor() {
      super();
      this.name = "main";
      this.url = MAIN_WINDOW_WEBPACK_ENTRY;
      this.iconPath = path.join(__dirname, "img", "logo.ioc");
      this.win = new BrowserWindow({
        webPreferences: {
          nodeIntegration: true,
          webSecurity: false,
          webviewTag: true
        },
        width: 985,
        height: 666,
        // frame: false,
        title: "前端大狗",
        hasShadow: true,
        minWidth: 980,
        minHeight: 660,
        show: false,
        maximizable: true, // 不可以最大化
        minimizable: true, // 不可以最小化
        transparent: false, // 透明 窗体透明背景后，窗体边框的阴影也是不存在的，
        icon: nativeImage.createFromPath('src/assets/img/logo.ico'),
        titleBarStyle: "hiddenInset"
      });
      global.mainWindowId = this.win.webContents.id;
  
      this.win.on("closed", () => {
        this.win = null;
      });

  
      // 最大化
      this.win.on("maximize", () => {
        this.win.webContents.send("change-win-status", true);
      });
  
      // 退出最大化
      this.win.on("unmaximize", () => {
        this.win.webContents.send("change-win-status", false);
      });
  
      // 全屏
      this.win.on("enter-full-screen", () => {
        this.win.webContents.send("change-win-status", true);
      });
  
      // 退出全屏
      this.win.on("leave-full-screen", () => {
        this.win.webContents.send("change-win-status", false);
      });
  
      if (process.platform === "darwin") {
        this.win.once("show", () => {
          // app.loginWindow.hide();
        });
      }
  
      this.win.on("focus", () => {
          console.log("win获得焦点");
          console.log(this.iconPath);
      });
  
      this.win.on("close", event => {
        event.preventDefault();
        console.log("win关闭");
        this.hide();
      });

      this.registerListener("action-start-flash", (event) => {
        app.tray.startFlash();
      });
    }
  }
  